const transmit = (nodes, id, store) => {
  for (const node of nodes) {
    if (node.value === id) {
      store.push(node.value)
      return true
    } else if (node.children) {
      store.push(node.value)
      if (!transmit(node.children, id, store)) {
        store.pop()
      }
    }
  }
  return false
}
const traverse = (nodes, keyName, childName, store) => {
  for (const node of nodes) {
    if (!node[childName] || !node[childName].length) {
      store.push(node[keyName])
    } else {
      traverse(node[childName], keyName, childName, store)
    }
  }
}
export default class TreeUtil {
  static getPath(treeData, id) {
    const store = []
    transmit(treeData, id, store)
    return store
  }

  static getLeafNodes(nodes, keyName = 'id', childName = 'children') {
    const store = []
    traverse(nodes, keyName, childName, store)
    return store
  }
}
